﻿using S7.Net;
using System;
using System.Collections.Generic;
using System.Text;

namespace hyjx.comm.Interfaces
{
    /// <summary>
    /// S7 协议
    /// </summary>
    public interface IS7Protocol : IPlcProtocol
    {
        /// <summary>
        /// Cpu 类型
        /// </summary>
        CpuType Cpu { get; }
        /// <summary>
        /// 写值
        /// </summary>
        /// <typeparam name="T">值类型</typeparam>
        /// <param name="address">寄存器地址</param>
        /// <param name="value">写入的值</param>
        void Write<T>(string address, T value) where T : new();
        /// <summary>
        /// 写值
        /// </summary>
        /// <param name="db">数据块号</param>
        /// <param name="startByteAdrress">起始寄存器地址</param>
        /// <param name="bytes">写入的字节流</param>
        void Write(int db, int startByteAdrress, byte[] bytes);
        /// <summary>
        /// 写值
        /// </summary>
        /// <param name="db">数据块号</param>
        /// <param name="address">地址</param>
        /// <param name="value">写入的值</param>
        void Write(int db, int address, short value);
        /// <summary>
        /// 写值
        /// </summary>
        /// <param name="db">数据块号</param>
        /// <param name="address">地址</param>
        /// <param name="value">写入的值</param>
        void Write(int db, int address, float value);
        /// <summary>
        /// 写值
        /// </summary>
        /// <param name="db">数据块号</param>
        /// <param name="address">地址</param>
        /// <param name="value">写入的值</param>
        void Write(int db, float address, bool value);
        /// <summary>
        /// 写值
        /// </summary>
        /// <param name="db">数据块号</param>
        /// <param name="address">地址</param>
        /// <param name="addressLength">地址长度</param>
        /// <param name="text">写入的文本</param>
        void Write(int db, int address, byte addressLength, string text);
        /// <summary>
        /// 读取整型值
        /// </summary>
        /// <param name="address">寄存器地址</param>
        /// <returns></returns>
        int ReadInt(string address);
        /// <summary>
        /// 读取布尔值
        /// </summary>
        /// <param name="address">寄存器地址</param>
        /// <returns></returns>
        bool ReadBool(string address);
        /// <summary>
        /// 读取浮点值
        /// </summary>
        /// <param name="address">寄存器地址</param>
        /// <returns></returns>
        float ReadFloat(string address);
        /// <summary>
        /// 读取字节流
        /// </summary>
        /// <param name="db">数据块号</param>
        /// <param name="startByteAddress">起始寄存器地址</param>
        /// <param name="length">读取字节长度</param>
        /// <returns></returns>
        byte[] ReadBytes(int db, int startByteAddress, int length);
        /// <summary>
        /// 读取字符串
        /// </summary>
        /// <param name="db">数据块号</param>
        /// <param name="startByteAddress">起始寄存器地址</param>
        /// <param name="length">字节长度（依据 S7 规则，字符串的长度是 n + 2）</param>
        /// <returns></returns>
        string ReadString(int db, int startByteAddress, int length);

    }
}
